package com.td.server.state;

import com.td.core.communication.obj.GameStateInfo.STATE;
import com.td.core.globals.TDGlobals;
import com.td.core.obj.Player;
import com.td.core.obj.TDGame;
import com.td.core.obj.utils.TDTimer2;
import com.td.server.obj.TDBot;

public class BuildingState extends State{

	public TDTimer2 timer;
	
	public BuildingState(TDGame game) {
		super(game);
	}

	public void init(int level) {
		game.getStateInfo().setCurrentState(STATE.BUILDING);
		game.getStateInfo().setCurrentLevel(level);
		if(level == 1)
			timer = new TDTimer2(400);
		else
			timer = new TDTimer2(200);
		
		setEnd(false);
		
		if(level == TDGlobals.maxLevel)
			for(Player player : game.getPlayers())
				player.setGameOver(true);
	}
	
	@Override
	public void update() {

		if(timer.update()) {
			setEnd(true);
		}
		
		for(Player pl: game.getPlayers()) {
			if(pl instanceof TDBot && !pl.isGameOver()) {
				((TDBot) pl).update();
			}
		}
	}
}
